﻿using Easy.Common.Extension;
using Easy.Common.Helper.JWT;
using Microsoft.AspNetCore.Mvc;

namespace Easy.API.Controllers
{
    /// <summary>
    /// Base
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class BaseController : ControllerBase
    {
        /// <summary>
        /// 当前登录信息
        /// </summary>
        internal TokenModelJwt TokenModel
        {
            //AutofacDependencyResolver
            get
            {
                TokenModelJwt tokenModel = new();
                var token = HttpContext.Request.Headers["Authorization"];
                if (!token.ToString().IsNullOrWhiteSpace())
                {
                    tokenModel = JwtHelper.DecodeJwt(token.ToString().Replace("Bearer ", "").Trim());
                }
                return tokenModel;
            }
        }

    }
}
